package cn.ithers.blog.controller.portal;

import cn.ithers.blog.annotion.CheckTooFrequentCommit;
import cn.ithers.blog.dto.CommentDTO;
import cn.ithers.blog.pojo.Comment;
import cn.ithers.blog.response.ResponseResult;
import cn.ithers.blog.service.ICommentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: zhanghuan
 * @date: 2020/8/28 14:40
 * @description:
 */
@Api(value = "评论", tags = "评论")
@RestController
@RequestMapping("/portal/comment")
public class CommentPortalApi {

    @Autowired
    private ICommentService commentService;

    /**
     * 添加评论
     *
     * @param commentDTO
     * @return
     */
    @CheckTooFrequentCommit
    @ApiOperation("添加评论")
    @PostMapping()
    public ResponseResult PostComment(@RequestBody CommentDTO commentDTO) {
        return commentService.postComment(commentDTO);
    }

    /**
     * 删除批评
     *
     * @param commentId
     * @return
     */

    @ApiOperation("删除批评")
    @DeleteMapping("/{commentId}")
    public ResponseResult deleteComment(@ApiParam(value = "评论ID",required = true) @PathVariable("commentId") String commentId) {
        return commentService.deleteComment(commentId);
    }


    /**
     * 获取评论列表list
     *
     * @param articleId
     * @return
     */
    @ApiOperation("获取评论列表")
    @GetMapping("/list/{articleId}/{page}/{pageSize}")
    public ResponseResult listComments(
            @ApiParam(value = "文章ID",required = true) @PathVariable("articleId") String articleId,
            @ApiParam(value = "当前页码",required = true) @PathVariable("page") int page,
            @ApiParam(value = "每页显示条数",required = true) @PathVariable("pageSize") int pageSize) {
        return commentService.listComments(articleId, page, pageSize);
    }


}
